package com.yiqi.liebang.feature.home.view.adapter;

import android.text.TextUtils;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.suozhang.framework.framework.AM;
import com.yiqi.liebang.R;
import com.yiqi.liebang.entity.bo.SearchFriendBo;

import java.util.Vector;

public class ChoiceExpertAdpter extends BaseQuickAdapter<SearchFriendBo.UserFriendBean, BaseViewHolder> {

    private int lastPosition = -1;                                //记录上一次选中的图片位置，-1表示未选中
    private Vector<Boolean> vector = new Vector<Boolean>();


    public ChoiceExpertAdpter() {
        super(R.layout.item_home_friends_search);
        for (int i = 0; i < 10; i++) {
            vector.add(false);
        }
    }

    @Override
    protected void convert(BaseViewHolder helper, SearchFriendBo.UserFriendBean item) {

        helper.setImageResource(R.id.iv_expert_select,
                vector.elementAt(helper.getPosition()) ?
                        R.drawable.list_button_select : R.drawable.list_btn_normal)
                .setText(R.id.iv_friend_name, item.getUserName())
                .setText(R.id.iv_friend_position,
                        TextUtils.isEmpty(item.getPosition()) ? "" : item.getPosition())
                .setVisible(R.id.iv_user_position, item.getIsOccupation() == 1 ? true : false)
                .setVisible(R.id.iv_user_certification, item.getIsBasic() == 1 ? true : false)

        ;
        AM.image().bindToCircleObject(item.getUserHead(), helper.getView(R.id.iv_friend_head));
    }


    public void changeState(int position) {
        if (lastPosition != -1){
            vector.setElementAt(false, lastPosition);                   //取消上一次的选中状态
        vector.setElementAt(!vector.elementAt(position), position);     //直接取反即可
        lastPosition = position;                                        //记录本次选中的位置
        notifyDataSetChanged(); }                                        //通知适配器进行更新
    }


}
